.PHONY: all clean menuconfig

PYTHON = python3
RM = rm

PARSE_CONFIG_SCRIPT = $(abspath tools/parse_config.py)

# ifeq ($(wildcard .config),)
# 	$(error .config not exist, please run make menuconfig first ...)
# else
CONFIG_DEFINES := $(shell $(PYTHON) $(PARSE_CONFIG_SCRIPT) .config)
# endif

export MENUCONFIG_STYLE=aquatic

ifndef VERBOSE
MAKEFLAGS += --no-print-directory
endif

all:
	@echo "Configured with: $(CONFIG_DEFINES)"
	@cmake -S . -B build -G "Unix Makefiles" -DCMAKE_EXPORT_COMPILE_COMMANDS=1 $(CONFIG_DEFINES)
	@cd build && make -j4

clean:
	@$(RM) -rf build

menuconfig:
	@$(PYTHON) tools/Kconfiglib/menuconfig.py Kconfig
	@$(PYTHON) tools/Kconfiglib/genconfig.py --header-path app_config.h
	@$(RM) -rf build
